package com.cch.cooperation.api.zone.controller;

import com.cch.cooperation.api.auth.dto.LoginUserDTO;
import com.cch.cooperation.api.common.request.IdReq;
import com.cch.cooperation.api.zone.dto.ZonePostCommentAddDTO;
import com.cch.cooperation.api.zone.dto.ZonePostCommentDTO;
import com.cch.cooperation.api.zone.service.ZonePostCommentServiceImpl;
import com.cch.cooperation.common.web.response.Response;
import com.cch.cooperation.common.web.session.Session;
import com.cch.cooperation.common.web.session.SessionManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 空间动态点赞接口
 *
 * @author cch
 */
@Api(tags = "空间动态评论接口")
@RestController
@RequestMapping("/api/zone/post/comment")
public class ZonePostCommentController {

    @Resource
    private ZonePostCommentServiceImpl zonePostCommentService;
    @Resource
    private SessionManager sessionManager;

    @ApiOperation("添加评论")
    @PostMapping("/add")
    public Response<ZonePostCommentDTO> add(@RequestBody ZonePostCommentAddDTO req) {
        Session<LoginUserDTO> session = sessionManager.get();
        req.setUserId(session.getData().getId());
        ZonePostCommentDTO data = zonePostCommentService.add(req);
        return Response.success(data);
    }

    @ApiOperation("根据id删除")
    @PostMapping("/deleteById")
    public Response<Void> deleteById(@RequestBody IdReq req) {
        zonePostCommentService.deleteById(req.getId());
        return Response.success();
    }

}
